package old;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.ScrollPanel;
import com.google.gwt.user.client.ui.VerticalPanel;

public class ChatTab extends Composite {
	// #Name des Tabs, #Gruppenmitglieder, #Chat
	UserGroup userGroups;

	VerticalPanel tabHPanel = new VerticalPanel();

	String tabName;
	Label tabMemberLabel = new Label();

	ScrollPanel wrapperPanel = new ScrollPanel();
	FlexTable flexTable = new FlexTable();

	// TextArea tabChatLog = new TextArea();

	public ChatTab(int width, int height, String groupName, String[] groupMember) {
		initWidget(tabHPanel);

		userGroups = new UserGroup(groupName, groupMember);

		tabName = groupName;
		tabMemberLabel.setText(userGroups.toString());
		tabMemberLabel.setPixelSize(width - 25, 20);
		tabHPanel.add(tabMemberLabel);

		/*
		 * tabChatLog.setPixelSize(width - 25, height - 70);
		 * tabChatLog.setReadOnly(true);
		 */
		
		wrapperPanel.setPixelSize(790, 430);
		wrapperPanel.setAlwaysShowScrollBars(true);

		HorizontalPanel hpanel = new HorizontalPanel();
		hpanel.setPixelSize(width -30, height - 80);
		flexTable.setPixelSize(width -40, height - 90);
		hpanel.add(flexTable);
		
		

		wrapperPanel.add(hpanel);
		tabHPanel.add(wrapperPanel);
	}

	public void addNewMessage(String newMessage) {
		flexTable.setText(flexTable.getRowCount(), 2, newMessage);
		flexTable.setText(flexTable.getRowCount()-1, 1, "Pascal");
		flexTable.setWidget(flexTable.getRowCount()-1, 0, new Button("like"));
		flexTable.getFlexCellFormatter().setColSpan(flexTable.getRowCount()-1, 2, 2);
		flexTable.getColumnFormatter().setWidth(0, "50px");
		flexTable.getColumnFormatter().setWidth(1, "150px");
		flexTable.getColumnFormatter().setWidth(2, "150px");
		wrapperPanel.scrollToBottom();
	}
}
